package org.jeecg.modules.manage.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.CommonUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.manage.entity.StyleAccessoryInfo;
import org.jeecg.modules.manage.entity.StyleElectroplateInfo;
import org.jeecg.modules.manage.entity.StyleInfo;
import org.jeecg.modules.manage.entity.StyleOtherInfo;
import org.jeecg.modules.manage.entity.StyleStoneInfo;
import org.jeecg.modules.manage.entity.StyleSuitInfo;
import org.jeecg.modules.manage.entity.StyleWorkingProcedure;
import org.jeecg.modules.manage.service.IStyleAccessoryInfoService;
import org.jeecg.modules.manage.service.IStyleElectroplateInfoService;
import org.jeecg.modules.manage.service.IStyleInfoService;
import org.jeecg.modules.manage.service.IStyleOtherInfoService;
import org.jeecg.modules.manage.service.IStyleStoneInfoService;
import org.jeecg.modules.manage.service.IStyleSuitInfoService;
import org.jeecg.modules.manage.service.IStyleWorkingProcedureService;
import org.jeecg.modules.system.service.ISysDictService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

 /**
 * @Description: 款式资料
 * @Author: jeecg-boot
 * @Date:   2021-09-06
 * @Version: V1.0
 */
@Api(tags="款式资料")
@RestController
@RequestMapping("/styleInfo/styleInfo")
@Slf4j
public class StyleInfoController extends JeecgController<StyleInfo, IStyleInfoService> {
	
	public static String IMG_TYPE_PNG = "PNG";
    public static String IMG_TYPE_JPG = "JPG";
    public static String IMG_TYPE_JPEG = "JPEG";
    public static String IMG_TYPE_BMP = "BMP";
    public static String IMG_TYPE_GIF = "GIF";
    public static String IMG_TYPE_SVG = "SVG";

	@Autowired
	private IStyleInfoService styleInfoService;

	@Autowired
	private IStyleStoneInfoService styleStoneInfoService;

	@Autowired
	private IStyleAccessoryInfoService styleAccessoryInfoService;

	@Autowired
	private IStyleWorkingProcedureService styleWorkingProcedureService;

	@Autowired
	private IStyleElectroplateInfoService styleElectroplateInfoService;

	@Autowired
	private IStyleSuitInfoService styleSuitInfoService;

	@Autowired
	private IStyleOtherInfoService styleOtherInfoService;
	
	@Autowired
    private ISysDictService sysDictService;
	
	@Value("${jeecg.path.upload}")
    private String uploadPath;


	/*---------------------------------主表处理-begin-------------------------------------*/

	/**
	 * 分页列表查询
	 * @param styleInfo
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "款式资料-分页列表查询")
	@ApiOperation(value="款式资料-分页列表查询", notes="款式资料-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(StyleInfo styleInfo,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<StyleInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleInfo, req.getParameterMap());
		queryWrapper.orderByDesc("create_time");
		Page<StyleInfo> page = new Page<StyleInfo>(pageNo, pageSize);
		IPage<StyleInfo> pageList = styleInfoService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
     *   添加
     * @param styleInfo
     * @return
     */
    @AutoLog(value = "款式资料-添加")
    @ApiOperation(value="款式资料-添加", notes="款式资料-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody StyleInfo styleInfo) {
    	styleInfo.setCodeNum(CommonUtils.replaceBlank(styleInfo.getCodeNum()));//去掉特殊字符
    	styleInfo.setName(CommonUtils.replaceBlank(styleInfo.getName()));//去掉特殊字符
    	styleInfo.setName((styleInfo.getName() == null || "".equals(styleInfo.getName())) ? styleInfo.getCodeNum() : styleInfo.getName());
        styleInfoService.save(styleInfo);
        return Result.OK("添加成功！");
    }

    /**
     *  编辑
     * @param styleInfo
     * @return
     */
    @AutoLog(value = "款式资料-编辑")
    @ApiOperation(value="款式资料-编辑", notes="款式资料-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody StyleInfo styleInfo) {
    	styleInfo.setCodeNum(CommonUtils.replaceBlank(styleInfo.getCodeNum()));//去掉特殊字符
    	styleInfo.setName(CommonUtils.replaceBlank(styleInfo.getName()));//去掉特殊字符
    	styleInfo.setName((styleInfo.getName() == null || "".equals(styleInfo.getName())) ? styleInfo.getCodeNum() : styleInfo.getName());
        styleInfoService.updateById(styleInfo);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     * @param id
     * @return
     */
    @AutoLog(value = "款式资料-通过id删除")
    @ApiOperation(value="款式资料-通过id删除", notes="款式资料-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name="id",required=true) String id) {
        styleInfoService.delMain(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @AutoLog(value = "款式资料-批量删除")
    @ApiOperation(value="款式资料-批量删除", notes="款式资料-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        this.styleInfoService.delBatchMain(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, StyleInfo styleInfo) {
        return super.exportXls(request, styleInfo, StyleInfo.class, "款式资料");
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
       // return super.importExcel(request, response, StyleInfo.class);
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        String verifyCodeNumType = request.getParameter("verifyCodeNumType");//1=跳过相同款号 2=覆盖相同款号
        if(verifyCodeNumType == null || "".equals(verifyCodeNumType)) {
        	verifyCodeNumType = "1";
        }
		Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		List<StyleInfo> saveList = new ArrayList<>();//新增数据集合
		List<StyleInfo> updateList = new ArrayList<>();//更新数据集合
		List<StyleInfo> list = new ArrayList<>();//Excel数据集合
		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			MultipartFile file = entity.getValue();// 获取上传文件对象
			ImportParams params = new ImportParams();
			params.setTitleRows(2);
			params.setHeadRows(1);
			params.setNeedSave(true);
			try {
				list = ExcelImportUtil.importExcel(file.getInputStream(), StyleInfo.class, params);
				if(null != list && !list.isEmpty()) {
					for (int i = 0; i < list.size(); i++) {
						StyleInfo vo = list.get(i); 
						String codeNum = vo.getCodeNum();//款号

						if(codeNum == null || "".equals(codeNum)) {
							return Result.error("第"+(i+1)+"行：款号不能为空！");
						}
						QueryWrapper<StyleInfo> queryWrapper = new QueryWrapper<>();
						queryWrapper.eq("code_num", vo.getCodeNum());
						StyleInfo queryStyleInfo =  this.styleInfoService.getOne(queryWrapper);
						//if(queryStyleInfo != null) {
						//	return Result.error("第"+(i+1)+"行：系统中已存在款号为”"+vo.getCodeNum()+"“的数据！");
						//}
						if(queryStyleInfo != null) {
							if("1".equals(verifyCodeNumType)) {//跳过
								continue;
							} else if ("2".equals(verifyCodeNumType)) {//覆盖
		        				BeanUtils.copyProperties(vo, queryStyleInfo,  new String[] { "id", "create_by", "create_time", "update_by", "update_time"});
		        				updateList.add(queryStyleInfo);
							}
						} else {
							saveList.add(vo);
						}
					}
				}
			} catch (Exception e) {
				log.error(e.getMessage(), e);
			} finally {
				try {
					file.getInputStream().close();
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
		}
		String returnMsg = "EXCEL总共"+list.size()+"行数据";
		if(saveList.size() > 0) {//新增
			boolean isSuc = this.styleInfoService.saveBatch(saveList);
			if(isSuc) {
				returnMsg += "，" + "成功新增了"+saveList.size()+"条款式";
			}
		}
		if(updateList.size() > 0) {//更新
			boolean isSuc = this.styleInfoService.updateBatchById(updateList);
			if(isSuc) {
				if(saveList.size() > 0) {
					returnMsg += "，" + "更新了"+updateList.size()+"条款式！";
				} else {
					returnMsg += "，" + "成功更新了"+updateList.size()+"条款式！";
				}
			}		
		}
		if(saveList.size()  == 0 && updateList.size() == 0) {
			returnMsg += "，" + "本次导入0条！"; 
		}
		return Result.ok(returnMsg);
    }
    
    
    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/uploadPicDirUrl", method = RequestMethod.POST)
    public Result<?> uploadPicDirUrl(HttpServletRequest request, HttpServletResponse response) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        String verifyCodeNumType = request.getParameter("verifyCodeNumType");//1=跳过相同款号 2=覆盖相同款号
        if(verifyCodeNumType == null || "".equals(verifyCodeNumType)) {//如果为空，则默认是跳过相同款号
        	verifyCodeNumType = "1";
        }
		Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		List<StyleInfo> saveList = new ArrayList<>();//新增数据集合
		List<StyleInfo> updateList = new ArrayList<>();//更新数据集合
		int picCount = 0;//文件夹内的图片张数
		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			MultipartFile file = entity.getValue();// 获取上传文件对象
			try {
				String originalFileName = file.getOriginalFilename();
				if(originalFileName != null && !"".equals(originalFileName)) {
					String fileSuffix = originalFileName.substring(originalFileName.lastIndexOf(".") + 1);
					if(IMG_TYPE_PNG.equals(fileSuffix.toUpperCase())
						|| IMG_TYPE_JPG.equals(fileSuffix.toUpperCase())
						|| IMG_TYPE_JPEG.equals(fileSuffix.toUpperCase())
						|| IMG_TYPE_BMP.equals(fileSuffix.toUpperCase())
						|| IMG_TYPE_GIF.equals(fileSuffix.toUpperCase())
						|| IMG_TYPE_SVG.equals(fileSuffix.toUpperCase())) {
						QueryWrapper<StyleInfo> queryWrapper = new QueryWrapper<>();
						originalFileName = CommonUtils.replaceBlank(originalFileName);
						String codeNum = originalFileName.substring(originalFileName.lastIndexOf("/")+1,originalFileName.lastIndexOf("."));
						queryWrapper.eq("code_num", codeNum);

						StyleInfo queryStyleInfo = this.styleInfoService.getOne(queryWrapper);
						
						if (queryStyleInfo != null) {
							if ("1".equals(verifyCodeNumType)) {// 跳过
								continue;
							} else if ("2".equals(verifyCodeNumType)) {// 覆盖
								String savePath = CommonUtils.uploadLocal(file,"import",uploadPath);//上传图片
								queryStyleInfo.setStyleImagePath(savePath);
								updateList.add(queryStyleInfo);
							}
						} else {
							String savePath = CommonUtils.uploadLocal(file,"import",uploadPath);//上传图片
							StyleInfo addInfo = new StyleInfo();
							addInfo.setStyleImagePath(savePath);
							addInfo.setCodeNum(codeNum);
							addInfo.setName(codeNum);
							saveList.add(addInfo);
						}
						picCount++;
					}
				}
				
			} catch (Exception e) {
				log.error(e.getMessage(), e);
			} finally {
				try {
					file.getInputStream().close();
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
		}
		boolean isSuc = false;
		if(!updateList.isEmpty()) {
			isSuc = this.styleInfoService.updateBatchById(updateList);
		} 
		if(!saveList.isEmpty()) {
			isSuc = this.styleInfoService.saveBatch(saveList);
		}
		
		//String returnMsg = "文件夹内共"+picCount+"张图片，本次成功更新了"+(updateList.size()+saveList.size())+"条款式！";
		return isSuc ? Result.OK(1) : Result.OK(0);
   
		/*if(saveList.size() > 0) {//新增
			boolean isSuc = this.styleInfoService.saveBatch(saveList);
			if(isSuc) {
				returnMsg += "，" + "成功新增了"+saveList.size()+"条款式";
			}
		}
		if(updateList.size() > 0) {//更新
			boolean isSuc = this.styleInfoService.updateBatchById(updateList);
			if(isSuc) {
				if(saveList.size() > 0) {
					returnMsg += "，" + "更新了"+updateList.size()+"条款式！";
				} else {
					returnMsg += "，" + "成功更新了"+updateList.size()+"条款式！";
				}
			}		
		}
		if(saveList.size()  == 0 && updateList.size() == 0) {
			returnMsg += "，" + "本次导入0条款式！"; 
		}*/
    }
   
    
    
    
	/*---------------------------------主表处理-end-------------------------------------*/
	

    /*--------------------------------子表处理-配石资料-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	@AutoLog(value = "配石资料-通过主表ID查询")
	@ApiOperation(value="配石资料-通过主表ID查询", notes="配石资料-通过主表ID查询")
	@GetMapping(value = "/listStyleStoneInfoByMainId")
    public Result<?> listStyleStoneInfoByMainId(StyleStoneInfo styleStoneInfo,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<StyleStoneInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleStoneInfo, req.getParameterMap());
        Page<StyleStoneInfo> page = new Page<StyleStoneInfo>(pageNo, pageSize);
        IPage<StyleStoneInfo> pageList = styleStoneInfoService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param styleStoneInfo
	 * @return
	 */
	@AutoLog(value = "配石资料-添加")
	@ApiOperation(value="配石资料-添加", notes="配石资料-添加")
	@PostMapping(value = "/addStyleStoneInfo")
	public Result<?> addStyleStoneInfo(@RequestBody StyleStoneInfo styleStoneInfo) {
		styleStoneInfoService.save(styleStoneInfo);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param styleStoneInfo
	 * @return
	 */
	@AutoLog(value = "配石资料-编辑")
	@ApiOperation(value="配石资料-编辑", notes="配石资料-编辑")
	@PutMapping(value = "/editStyleStoneInfo")
	public Result<?> editStyleStoneInfo(@RequestBody StyleStoneInfo styleStoneInfo) {
		styleStoneInfoService.updateById(styleStoneInfo);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "配石资料-通过id删除")
	@ApiOperation(value="配石资料-通过id删除", notes="配石资料-通过id删除")
	@DeleteMapping(value = "/deleteStyleStoneInfo")
	public Result<?> deleteStyleStoneInfo(@RequestParam(name="id",required=true) String id) {
		styleStoneInfoService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "配石资料-批量删除")
	@ApiOperation(value="配石资料-批量删除", notes="配石资料-批量删除")
	@DeleteMapping(value = "/deleteBatchStyleStoneInfo")
	public Result<?> deleteBatchStyleStoneInfo(@RequestParam(name="ids",required=true) String ids) {
	    this.styleStoneInfoService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportStyleStoneInfo")
    public ModelAndView exportStyleStoneInfo(HttpServletRequest request, StyleStoneInfo styleStoneInfo) {
		 // Step.1 组装查询条件
		 QueryWrapper<StyleStoneInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleStoneInfo, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<StyleStoneInfo> pageList = styleStoneInfoService.list(queryWrapper);
		 List<StyleStoneInfo> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 mv.addObject(NormalExcelConstants.FILE_NAME, "配石资料"); //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.CLASS, StyleStoneInfo.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("配石资料报表", "导出人:" + sysUser.getRealname(), "配石资料"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importStyleStoneInfo/{mainId}")
    public Result<?> importStyleStoneInfo(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			 MultipartFile file = entity.getValue();// 获取上传文件对象
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<StyleStoneInfo> list = ExcelImportUtil.importExcel(file.getInputStream(), StyleStoneInfo.class, params);
				 for (StyleStoneInfo temp : list) {
					 String codeNum = temp.getCodeNum();// 石号
					 String styleInfoId = temp.getStyleInfoId(); // 款号
					 if (styleInfoId == null || "".equals(styleInfoId)) {
						 temp.setStyleInfoId(mainId);
					 }
					 if(codeNum == null || "".equals(codeNum)) {//如果石号为空，则尝试从系统中根据石号名称、形状、筛号等信息找出匹配的石号
						 String name = temp.getName();//石号名称
						 String shape = temp.getShape();//形状
						 String sizeNum = temp.getSizeNum();//筛号
						 String shapeT = sysDictService.queryDictTextByKey("shape", shape);
						 //sysDictService.quer
						 
					 }
				 }
				 long start = System.currentTimeMillis();
				 styleStoneInfoService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.ok("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-配石资料-end----------------------------------------------*/

    /*--------------------------------子表处理-配件资料-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	@AutoLog(value = "配件资料-通过主表ID查询")
	@ApiOperation(value="配件资料-通过主表ID查询", notes="配件资料-通过主表ID查询")
	@GetMapping(value = "/listStyleAccessoryInfoByMainId")
    public Result<?> listStyleAccessoryInfoByMainId(StyleAccessoryInfo styleAccessoryInfo,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<StyleAccessoryInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleAccessoryInfo, req.getParameterMap());
        Page<StyleAccessoryInfo> page = new Page<StyleAccessoryInfo>(pageNo, pageSize);
        IPage<StyleAccessoryInfo> pageList = styleAccessoryInfoService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param styleAccessoryInfo
	 * @return
	 */
	@AutoLog(value = "配件资料-添加")
	@ApiOperation(value="配件资料-添加", notes="配件资料-添加")
	@PostMapping(value = "/addStyleAccessoryInfo")
	public Result<?> addStyleAccessoryInfo(@RequestBody StyleAccessoryInfo styleAccessoryInfo) {
		styleAccessoryInfoService.save(styleAccessoryInfo);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param styleAccessoryInfo
	 * @return
	 */
	@AutoLog(value = "配件资料-编辑")
	@ApiOperation(value="配件资料-编辑", notes="配件资料-编辑")
	@PutMapping(value = "/editStyleAccessoryInfo")
	public Result<?> editStyleAccessoryInfo(@RequestBody StyleAccessoryInfo styleAccessoryInfo) {
		styleAccessoryInfoService.updateById(styleAccessoryInfo);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "配件资料-通过id删除")
	@ApiOperation(value="配件资料-通过id删除", notes="配件资料-通过id删除")
	@DeleteMapping(value = "/deleteStyleAccessoryInfo")
	public Result<?> deleteStyleAccessoryInfo(@RequestParam(name="id",required=true) String id) {
		styleAccessoryInfoService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "配件资料-批量删除")
	@ApiOperation(value="配件资料-批量删除", notes="配件资料-批量删除")
	@DeleteMapping(value = "/deleteBatchStyleAccessoryInfo")
	public Result<?> deleteBatchStyleAccessoryInfo(@RequestParam(name="ids",required=true) String ids) {
	    this.styleAccessoryInfoService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportStyleAccessoryInfo")
    public ModelAndView exportStyleAccessoryInfo(HttpServletRequest request, StyleAccessoryInfo styleAccessoryInfo) {
		 // Step.1 组装查询条件
		 QueryWrapper<StyleAccessoryInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleAccessoryInfo, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<StyleAccessoryInfo> pageList = styleAccessoryInfoService.list(queryWrapper);
		 List<StyleAccessoryInfo> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 mv.addObject(NormalExcelConstants.FILE_NAME, "配件资料"); //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.CLASS, StyleAccessoryInfo.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("配件资料报表", "导出人:" + sysUser.getRealname(), "配件资料"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importStyleAccessoryInfo/{mainId}")
    public Result<?> importStyleAccessoryInfo(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			 MultipartFile file = entity.getValue();// 获取上传文件对象
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<StyleAccessoryInfo> list = ExcelImportUtil.importExcel(file.getInputStream(), StyleAccessoryInfo.class, params);
				 int i = 0;
				 for (StyleAccessoryInfo temp : list) {
					 String styleInfoId = temp.getStyleInfoId(); // 款号
					 if (styleInfoId == null || "".equals(styleInfoId)) {
						 temp.setStyleInfoId(mainId);
					 }
				 }
				 long start = System.currentTimeMillis();
				 styleAccessoryInfoService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.ok("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-配件资料-end----------------------------------------------*/

    /*--------------------------------子表处理-工序资料-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	@AutoLog(value = "工序资料-通过主表ID查询")
	@ApiOperation(value="工序资料-通过主表ID查询", notes="工序资料-通过主表ID查询")
	@GetMapping(value = "/listStyleWorkingProcedureByMainId")
    public Result<?> listStyleWorkingProcedureByMainId(StyleWorkingProcedure styleWorkingProcedure,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<StyleWorkingProcedure> queryWrapper = QueryGenerator.initQueryWrapper(styleWorkingProcedure, req.getParameterMap());
        Page<StyleWorkingProcedure> page = new Page<StyleWorkingProcedure>(pageNo, pageSize);
        IPage<StyleWorkingProcedure> pageList = styleWorkingProcedureService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param styleWorkingProcedure
	 * @return
	 */
	@AutoLog(value = "工序资料-添加")
	@ApiOperation(value="工序资料-添加", notes="工序资料-添加")
	@PostMapping(value = "/addStyleWorkingProcedure")
	public Result<?> addStyleWorkingProcedure(@RequestBody StyleWorkingProcedure styleWorkingProcedure) {
		styleWorkingProcedureService.save(styleWorkingProcedure);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param styleWorkingProcedure
	 * @return
	 */
	@AutoLog(value = "工序资料-编辑")
	@ApiOperation(value="工序资料-编辑", notes="工序资料-编辑")
	@PutMapping(value = "/editStyleWorkingProcedure")
	public Result<?> editStyleWorkingProcedure(@RequestBody StyleWorkingProcedure styleWorkingProcedure) {
		styleWorkingProcedureService.updateById(styleWorkingProcedure);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "工序资料-通过id删除")
	@ApiOperation(value="工序资料-通过id删除", notes="工序资料-通过id删除")
	@DeleteMapping(value = "/deleteStyleWorkingProcedure")
	public Result<?> deleteStyleWorkingProcedure(@RequestParam(name="id",required=true) String id) {
		styleWorkingProcedureService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "工序资料-批量删除")
	@ApiOperation(value="工序资料-批量删除", notes="工序资料-批量删除")
	@DeleteMapping(value = "/deleteBatchStyleWorkingProcedure")
	public Result<?> deleteBatchStyleWorkingProcedure(@RequestParam(name="ids",required=true) String ids) {
	    this.styleWorkingProcedureService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportStyleWorkingProcedure")
    public ModelAndView exportStyleWorkingProcedure(HttpServletRequest request, StyleWorkingProcedure styleWorkingProcedure) {
		 // Step.1 组装查询条件
		 QueryWrapper<StyleWorkingProcedure> queryWrapper = QueryGenerator.initQueryWrapper(styleWorkingProcedure, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<StyleWorkingProcedure> pageList = styleWorkingProcedureService.list(queryWrapper);
		 List<StyleWorkingProcedure> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 mv.addObject(NormalExcelConstants.FILE_NAME, "工序资料"); //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.CLASS, StyleWorkingProcedure.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("工序资料报表", "导出人:" + sysUser.getRealname(), "工序资料"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importStyleWorkingProcedure/{mainId}")
    public Result<?> importStyleWorkingProcedure(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			 MultipartFile file = entity.getValue();// 获取上传文件对象
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<StyleWorkingProcedure> list = ExcelImportUtil.importExcel(file.getInputStream(), StyleWorkingProcedure.class, params);
				 int i = 0;
				 for (StyleWorkingProcedure temp : list) {
					 String name = temp.getName();// 工序
					 String styleInfoId = temp.getStyleInfoId(); // 款号
					 if (name == null || "".equals(name)) {
						 return Result.error("第" + (i + 4) + "行：工序不能为空！");
					 } else if (styleInfoId == null || "".equals(styleInfoId)) {
						 return Result.error("第" + (i + 4) + "行：款号不能为空！");
					 }
					 i++;
                   // temp.setStyleInfoId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 styleWorkingProcedureService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.ok("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-工序资料-end----------------------------------------------*/

    /*--------------------------------子表处理-电镀资料-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	@AutoLog(value = "电镀资料-通过主表ID查询")
	@ApiOperation(value="电镀资料-通过主表ID查询", notes="电镀资料-通过主表ID查询")
	@GetMapping(value = "/listStyleElectroplateInfoByMainId")
    public Result<?> listStyleElectroplateInfoByMainId(StyleElectroplateInfo styleElectroplateInfo,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<StyleElectroplateInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleElectroplateInfo, req.getParameterMap());
        Page<StyleElectroplateInfo> page = new Page<StyleElectroplateInfo>(pageNo, pageSize);
        IPage<StyleElectroplateInfo> pageList = styleElectroplateInfoService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param styleElectroplateInfo
	 * @return
	 */
	@AutoLog(value = "电镀资料-添加")
	@ApiOperation(value="电镀资料-添加", notes="电镀资料-添加")
	@PostMapping(value = "/addStyleElectroplateInfo")
	public Result<?> addStyleElectroplateInfo(@RequestBody StyleElectroplateInfo styleElectroplateInfo) {
		styleElectroplateInfoService.save(styleElectroplateInfo);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param styleElectroplateInfo
	 * @return
	 */
	@AutoLog(value = "电镀资料-编辑")
	@ApiOperation(value="电镀资料-编辑", notes="电镀资料-编辑")
	@PutMapping(value = "/editStyleElectroplateInfo")
	public Result<?> editStyleElectroplateInfo(@RequestBody StyleElectroplateInfo styleElectroplateInfo) {
		styleElectroplateInfoService.updateById(styleElectroplateInfo);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "电镀资料-通过id删除")
	@ApiOperation(value="电镀资料-通过id删除", notes="电镀资料-通过id删除")
	@DeleteMapping(value = "/deleteStyleElectroplateInfo")
	public Result<?> deleteStyleElectroplateInfo(@RequestParam(name="id",required=true) String id) {
		styleElectroplateInfoService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "电镀资料-批量删除")
	@ApiOperation(value="电镀资料-批量删除", notes="电镀资料-批量删除")
	@DeleteMapping(value = "/deleteBatchStyleElectroplateInfo")
	public Result<?> deleteBatchStyleElectroplateInfo(@RequestParam(name="ids",required=true) String ids) {
	    this.styleElectroplateInfoService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportStyleElectroplateInfo")
    public ModelAndView exportStyleElectroplateInfo(HttpServletRequest request, StyleElectroplateInfo styleElectroplateInfo) {
		 // Step.1 组装查询条件
		 QueryWrapper<StyleElectroplateInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleElectroplateInfo, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<StyleElectroplateInfo> pageList = styleElectroplateInfoService.list(queryWrapper);
		 List<StyleElectroplateInfo> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 mv.addObject(NormalExcelConstants.FILE_NAME, "电镀资料"); //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.CLASS, StyleElectroplateInfo.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("电镀资料报表", "导出人:" + sysUser.getRealname(), "电镀资料"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importStyleElectroplateInfo/{mainId}")
    public Result<?> importStyleElectroplateInfo(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			 MultipartFile file = entity.getValue();// 获取上传文件对象
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<StyleElectroplateInfo> list = ExcelImportUtil.importExcel(file.getInputStream(), StyleElectroplateInfo.class, params);
				 int i = 0;
				 for (StyleElectroplateInfo temp : list) {
					 String name = temp.getName();// 电镀名称
					 String styleInfoId = temp.getStyleInfoId(); // 款号
					 if (name == null || "".equals(name)) {
						 return Result.error("第" + (i + 4) + "行：电镀名称不能为空！");
					 } else if (styleInfoId == null || "".equals(styleInfoId)) {
						 return Result.error("第" + (i + 4) + "行：款号不能为空！");
					 }
					 i++;
                    temp.setStyleInfoId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 styleElectroplateInfoService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.ok("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-电镀资料-end----------------------------------------------*/

    /*--------------------------------子表处理-套件资料-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	@AutoLog(value = "套件资料-通过主表ID查询")
	@ApiOperation(value="套件资料-通过主表ID查询", notes="套件资料-通过主表ID查询")
	@GetMapping(value = "/listStyleSuitInfoByMainId")
    public Result<?> listStyleSuitInfoByMainId(StyleSuitInfo styleSuitInfo,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<StyleSuitInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleSuitInfo, req.getParameterMap());
        Page<StyleSuitInfo> page = new Page<StyleSuitInfo>(pageNo, pageSize);
        IPage<StyleSuitInfo> pageList = styleSuitInfoService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param styleSuitInfo
	 * @return
	 */
	@AutoLog(value = "套件资料-添加")
	@ApiOperation(value="套件资料-添加", notes="套件资料-添加")
	@PostMapping(value = "/addStyleSuitInfo")
	public Result<?> addStyleSuitInfo(@RequestBody StyleSuitInfo styleSuitInfo) {
		styleSuitInfoService.save(styleSuitInfo);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param styleSuitInfo
	 * @return
	 */
	@AutoLog(value = "套件资料-编辑")
	@ApiOperation(value="套件资料-编辑", notes="套件资料-编辑")
	@PutMapping(value = "/editStyleSuitInfo")
	public Result<?> editStyleSuitInfo(@RequestBody StyleSuitInfo styleSuitInfo) {
		styleSuitInfoService.updateById(styleSuitInfo);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "套件资料-通过id删除")
	@ApiOperation(value="套件资料-通过id删除", notes="套件资料-通过id删除")
	@DeleteMapping(value = "/deleteStyleSuitInfo")
	public Result<?> deleteStyleSuitInfo(@RequestParam(name="id",required=true) String id) {
		styleSuitInfoService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "套件资料-批量删除")
	@ApiOperation(value="套件资料-批量删除", notes="套件资料-批量删除")
	@DeleteMapping(value = "/deleteBatchStyleSuitInfo")
	public Result<?> deleteBatchStyleSuitInfo(@RequestParam(name="ids",required=true) String ids) {
	    this.styleSuitInfoService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportStyleSuitInfo")
    public ModelAndView exportStyleSuitInfo(HttpServletRequest request, StyleSuitInfo styleSuitInfo) {
		 // Step.1 组装查询条件
		 QueryWrapper<StyleSuitInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleSuitInfo, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<StyleSuitInfo> pageList = styleSuitInfoService.list(queryWrapper);
		 List<StyleSuitInfo> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 mv.addObject(NormalExcelConstants.FILE_NAME, "套件资料"); //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.CLASS, StyleSuitInfo.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("套件资料报表", "导出人:" + sysUser.getRealname(), "套件资料"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importStyleSuitInfo/{mainId}")
    public Result<?> importStyleSuitInfo(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			 MultipartFile file = entity.getValue();// 获取上传文件对象
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<StyleSuitInfo> list = ExcelImportUtil.importExcel(file.getInputStream(), StyleSuitInfo.class, params);
				 int i = 0;
				 for (StyleSuitInfo temp : list) {
					 String suitNum = temp.getSuitNum();// 套件编号
					 String styleInfoId = temp.getStyleInfoId(); // 款号
					 if (suitNum == null || "".equals(suitNum)) {
						 return Result.error("第" + (i + 4) + "行：套件编号不能为空！");
					 } else if (styleInfoId == null || "".equals(styleInfoId)) {
						 return Result.error("第" + (i + 4) + "行：款号不能为空！");
					 }
					 i++;
                   // temp.setStyleInfoId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 styleSuitInfoService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.ok("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-套件资料-end----------------------------------------------*/

    /*--------------------------------子表处理-其他资料-begin----------------------------------------------*/
	/**
	 * 通过主表ID查询
	 * @return
	 */
	@AutoLog(value = "其他资料-通过主表ID查询")
	@ApiOperation(value="其他资料-通过主表ID查询", notes="其他资料-通过主表ID查询")
	@GetMapping(value = "/listStyleOtherInfoByMainId")
    public Result<?> listStyleOtherInfoByMainId(StyleOtherInfo styleOtherInfo,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<StyleOtherInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleOtherInfo, req.getParameterMap());
        Page<StyleOtherInfo> page = new Page<StyleOtherInfo>(pageNo, pageSize);
        IPage<StyleOtherInfo> pageList = styleOtherInfoService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

	/**
	 * 添加
	 * @param styleOtherInfo
	 * @return
	 */
	@AutoLog(value = "其他资料-添加")
	@ApiOperation(value="其他资料-添加", notes="其他资料-添加")
	@PostMapping(value = "/addStyleOtherInfo")
	public Result<?> addStyleOtherInfo(@RequestBody StyleOtherInfo styleOtherInfo) {
		styleOtherInfoService.save(styleOtherInfo);
		return Result.OK("添加成功！");
	}

    /**
	 * 编辑
	 * @param styleOtherInfo
	 * @return
	 */
	@AutoLog(value = "其他资料-编辑")
	@ApiOperation(value="其他资料-编辑", notes="其他资料-编辑")
	@PutMapping(value = "/editStyleOtherInfo")
	public Result<?> editStyleOtherInfo(@RequestBody StyleOtherInfo styleOtherInfo) {
		styleOtherInfoService.updateById(styleOtherInfo);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "其他资料-通过id删除")
	@ApiOperation(value="其他资料-通过id删除", notes="其他资料-通过id删除")
	@DeleteMapping(value = "/deleteStyleOtherInfo")
	public Result<?> deleteStyleOtherInfo(@RequestParam(name="id",required=true) String id) {
		styleOtherInfoService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "其他资料-批量删除")
	@ApiOperation(value="其他资料-批量删除", notes="其他资料-批量删除")
	@DeleteMapping(value = "/deleteBatchStyleOtherInfo")
	public Result<?> deleteBatchStyleOtherInfo(@RequestParam(name="ids",required=true) String ids) {
	    this.styleOtherInfoService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportStyleOtherInfo")
    public ModelAndView exportStyleOtherInfo(HttpServletRequest request, StyleOtherInfo styleOtherInfo) {
		 // Step.1 组装查询条件
		 QueryWrapper<StyleOtherInfo> queryWrapper = QueryGenerator.initQueryWrapper(styleOtherInfo, request.getParameterMap());
		 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		 // Step.2 获取导出数据
		 List<StyleOtherInfo> pageList = styleOtherInfoService.list(queryWrapper);
		 List<StyleOtherInfo> exportList = null;

		 // 过滤选中数据
		 String selections = request.getParameter("selections");
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		 } else {
			 exportList = pageList;
		 }

		 // Step.3 AutoPoi 导出Excel
		 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		 mv.addObject(NormalExcelConstants.FILE_NAME, "其他资料"); //此处设置的filename无效 ,前端会重更新设置一下
		 mv.addObject(NormalExcelConstants.CLASS, StyleOtherInfo.class);
		 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("其他资料报表", "导出人:" + sysUser.getRealname(), "其他资料"));
		 mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
		 return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importStyleOtherInfo/{mainId}")
    public Result<?> importStyleOtherInfo(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
		 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			 MultipartFile file = entity.getValue();// 获取上传文件对象
			 ImportParams params = new ImportParams();
			 params.setTitleRows(2);
			 params.setHeadRows(1);
			 params.setNeedSave(true);
			 try {
				 List<StyleOtherInfo> list = ExcelImportUtil.importExcel(file.getInputStream(), StyleOtherInfo.class, params);
				 for (StyleOtherInfo temp : list) {
                    temp.setStyleInfoId(mainId);
				 }
				 long start = System.currentTimeMillis();
				 styleOtherInfoService.saveBatch(list);
				 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
				 return Result.ok("文件导入成功！数据行数：" + list.size());
			 } catch (Exception e) {
				 log.error(e.getMessage(), e);
				 return Result.error("文件导入失败:" + e.getMessage());
			 } finally {
				 try {
					 file.getInputStream().close();
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-其他资料-end----------------------------------------------*/




}
